package com.youhong.teethcare.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class PreferencesUtils {

    private static final String FILENAME = "ORALSHARK";
    /**
     * get Personal_Info from SharedPreferences
     ***/


    private static SharedPreferences pre = null;

    public static SharedPreferences getPreferences(Context context) {

        return context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    }

    public static int ReadFromPreferencesInt(Context context, String key) {

        if (pre == null)
            pre = getPreferences(context);

        return pre.getInt(key, 0);

    }

    public static String ReadFromPreferencesString(Context context, String key) {

        if (pre == null)
            pre = getPreferences(context);

        return pre.getString(key, "");

    }

    public static boolean ReadFromPreferencesBoolean(Context context, String key) {

        if (pre == null)
            pre = getPreferences(context);

        return pre.getBoolean(key, false);

    }

    public static void WriteToPreferencesInt(Context context, String key, int value) {

        if (pre == null)
            pre = getPreferences(context);

        Editor editor = pre.edit();
        editor.putInt(key, value);
        editor.commit();

    }

    public static void WriteToPreferencesString(Context context, String key, String value) {

        if (pre == null)
            pre = getPreferences(context);

        Editor editor = pre.edit();
        editor.putString(key, value);
        editor.commit();

    }

    public static long ReadFromPreferencesLong(Context context, String key) {

        if (pre == null)
            pre = getPreferences(context);

        return pre.getLong(key, 0);

    }

    public static void WriteToPreferencesLong(Context context, String key, long value) {

        if (pre == null)
            pre = getPreferences(context);

        Editor editor = pre.edit();
        editor.putLong(key, value);
        editor.commit();

    }

    public static void WriteToPreferencesBoolean(Context context, String key, boolean value) {

        if (pre == null)
            pre = getPreferences(context);

        Editor editor = pre.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

}
